package com.develop.skwen.electricgomall.util;

import com.develop.skwen.basemodule.http.HttpManager;
import com.develop.skwen.electricgomall.find.model.FindBean;
import com.develop.skwen.electricgomall.find.model.FindResult;
import com.develop.skwen.electricgomall.http.ApiService;

import java.util.List;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.functions.Consumer;
import io.reactivex.functions.Function;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by skwen on 2018/7/8.
 */

public class FindDataUtil {


    private static FindDataUtil findDataUtil;

    private FindDataUtil() {

    }

    public static FindDataUtil getInstance() {
        if (findDataUtil == null) {
            synchronized (FindDataUtil.class) {
                if (findDataUtil == null) {
                    findDataUtil = new FindDataUtil();
                }
            }
        }
        return findDataUtil;
    }


    public void getFindDatas(Consumer<List<FindBean>> consumer) {

        HttpManager.getInstance().getHttpService(ApiService.class)
                .getListFindBeanData(0)
                .subscribeOn(Schedulers.io())
                .map(new Function<FindResult, List<FindBean>>() {
                    @Override
                    public List<FindBean> apply(FindResult findResult) throws Exception {
                        return findResult.getResult().getData();
                    }
                })
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(consumer);

//        HttpManager.getInstance().getHttpService(ApiService.class)
//                .getListFindBeanDatas(0)
//                .enqueue(new Callback<ResponseBody>() {
//                    @Override
//                    public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
//                        Log.d(getClass().getSimpleName(),response.body().toString());
//                    }
//
//                    @Override
//                    public void onFailure(Call<ResponseBody> call, Throwable t) {
//
//                    }
//                });
    }


}
